<script setup>
import { onMounted, ref } from 'vue';

const value = ref('');

var map = null;
onMounted(() => {
    map = new BMapGL.Map("container");
    var point = new BMapGL.Point(116.404, 39.915);
    map.centerAndZoom(point, 15);
    var zoomCtrl = new BMapGL.ZoomControl();  // 添加缩放控件
    map.addControl(zoomCtrl);

})

function onClickButton() {
    var local = new BMapGL.LocalSearch(map, {
        renderOptions: { map: map }
    });
    local.search(value.value);

}
</script>

<template>
    <div id="container"></div>
    <div class="map">
        <header class=" map-header">
            <div class="back" @click="$router.back()">
                <svg t="1731383206890" class="icon" viewBox="0 0 1024 1024" version="1.1"
                    xmlns="http://www.w3.org/2000/svg" p-id="2340" width="18" height="18">
                    <path
                        d="M733.090909 977.454545a23.202909 23.202909 0 0 1-16.453818-6.818909l-442.181818-442.158545a23.202909 23.202909 0 0 1 0-32.907636l442.181818-442.205091a23.249455 23.249455 0 1 1 32.907636 32.907636L323.816727 512.023273l425.728 425.704727A23.249455 23.249455 0 0 1 733.090909 977.454545z"
                        fill="" p-id="2341"></path>
                </svg>
            </div>

            <van-search v-model="value" show-action label="地址" placeholder="请输入搜索关键词">
                <template #action>
                    <div @click="onClickButton">搜索</div>
                </template>
            </van-search>
        </header>
    </div>
</template>

<style scoped lang="scss">
#container {
    height: 100%
}

.info {
    z-index: 999;
    width: auto;
    min-width: 22rem;
    padding: .75rem 1.25rem;
    margin-left: 1.25rem;
    position: fixed;
    top: 1rem;
    background-color: #fff;
    border-radius: .25rem;
    font-size: 14px;
    color: #666;
    box-shadow: 0 2px 6px 0 rgba(27, 142, 236, 0.5);
}

.map-header {
    width: 85%;
    display: flex;
    justify-content: space-around;
    align-items: center;
    position: absolute;
    top: 50px;
    left: 18px;
    border-radius: 35px;
    background-color: white;
    padding: 10px;
    z-index: 999;

    .van-search {
        width: 280px;
        height: 38px;
    }

    .van-button {
        width: 60px;
        height: 38px;
    }
}
</style>